/**
 * utils/read-front-routes
 */

const vm = require('vm');
const fsp = require('fs-extra');
const Promise = require('bluebird');

module.exports = file => {
    return Promise.try(() => {
        return fsp.readFile(file);
    })
    .then(buf => {
        const code = buf.toString();
        const script = new vm.Script(code);
        const vmGlobal = {
            require() {
                return null;
            },
            module: {
                exports: {}
            }
        };

        script.runInNewContext(vmGlobal);

        return vmGlobal.module.exports;
    });
};
